home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 220 < prev    next >
Text File  |  1996-08-06  |  7KB  |  150 lines

  1. Newsgroups: comp.lang.c,comp.std.c
  2. Path: blackbush.xlink.net!slsv6bt!slsv6bt!kanze
  3. From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
  4. Subject: Re: Integral conversion e.t.c. (was: Re: Hungarian notation)
  5. In-Reply-To: tanmoy@qcd.lanl.gov's message of 29 Jan 1996 16:05:18 GMT
  6. Message-ID: <KANZE.96Jan29201312@slsvewt.lts.sel.alcatel.de>
  7. Sender: news@lts.sel.alcatel.de
  8. Organization: SEL
  9. References: <30C40F77.53B5@swsbbs.com> <SPENCER.96Jan22113215@zorgon.ERA.COM>
  10.     <KANZE.96Jan26164833@gabi.gabi-soft.fr> <DLtABq.Fzu@mv.mv.com>
  11.     <4edqh2$rvl@solutions.solon.com>
  12.     <KANZE.96Jan29121956@slsvewt.lts.sel.alcatel.de>
  13.     <TANMOY.96Jan29090518@qcd.lanl.gov>
  14. Date: 29 Jan 1996 19:13:12 GMT
  15.  
  16. In article <TANMOY.96Jan29090518@qcd.lanl.gov> tanmoy@qcd.lanl.gov
  17. (Tanmoy Bhattacharya) writes:
  18.  
  19. |> In article <KANZE.96Jan29121956@slsvewt.lts.sel.alcatel.de>
  20. |> kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763) writes: 
  21. |> <snip>
  22. |>    I think the crux of Michael Furman's question lies therein.  Does the
  23. |>    standard require a diagnostic if the function main is not of one of
  24. |>    the two types given?
  25.  
  26. |> No diagnostic is _required_, but irrespective of whether a diagnostic
  27. |> is produced, there is no guarantee how the program will behave. This
  28. |> is a quintessential example of undefined behaviour. An implementation
  29. |> is free to define whatever meaning it chooses for this, exactly as it
  30. |> is free to change the meaning of the entire rest of the program based
  31. |> on this one statement.
  32.  
  33. Again, I think that one should make the distinction (at least in
  34. comp.lang.c) between undefined undefined by the standard, and really
  35. undefined.  The distinction is not defined in the standard, but is
  36. very present in real life.  Thus, dereferencing a NULL pointer is
  37. undefined, and while an implementation is free to define it if it
  38. likes, in practice, none will define it to do anything good.  Adding a
  39. third parameter to main is also undefined according to the C standard,
  40. but most Unix compilers (and maybe others) do define it in a very
  41. useful way; as far as I know, Posix may even define it so.
  42.  
  43. Although I find it hard to explain precisely the difference, I would
  44. generally consider counting on implementation defined behavior in
  45. derefencing the null pointer bad practice.  On the other hand, using
  46. the added parameter to main wouldn't particularly bother me,
  47. especially if, as is the case in most of my applications, the program
  48. is intimely bound to Unix anyway.
  49.  
  50. This is always a delicate line.  A Windows program using far and near
  51. pointers: I don't believe they can avoid it, and the program surely
  52. won't run on anyother platform without major modifications.  A filter
  53. program invoked from the DOS command line: I'd consider the use of far
  54. and near a major flaw, and would heartily condemn a design which
  55. required it.
  56.  
  57. |>    To tell the truth, I'm not sure what the answer is.  The text
  58. |>    concerning main is in the chapter describing the environment.  It
  59. |>    doesn't appear as a semantic restriction or anything.  It simply
  60. |>    states that on start-up, a function called main will be called, and
  61. |>    that the implementation must support the following forms.  It doesn't
  62. |>    seem (to me, at least) to say anything about what other forms it might
  63. |>    support, or what the implementation must do if given a fully other
  64. |>    definition of main.
  65.  
  66. |> And hence, it is an undefined behaviour.
  67.  
  68. |>    Normally, I would expect (at the very least) a compiler to generate a
  69. |>    warning or an error for a main that it did not support.  In fact,
  70. |>    however, my compiler (gcc) accepts the following definition without
  71. |>    the slightest complaint, although I'd rather not think about what will
  72. |>    happen when I access parameter d:
  73.  
  74. |>        int main( char a , int b , long c , double d )
  75.  
  76. |> Undefined behaviour does not need diagnostic.
  77.  
  78. Agreed.  The above comment was addressed more to comp.lang.c, and
  79. expresses what I would expect of a good compiler.  (Quality of
  80. implementation issue.)  If the compiler knows what your are doing will
  81. get you into trouble, and that there is no possible use for it, it
  82. should warn you.
  83.  
  84. |>    |> For purposes of the C newsgroups, discussion of what is/isn't legal
  85. |>    |> is generally restricted to strictly conforming C.
  86.  
  87. |>    Yes and no.  In comp.std.c, the discussion is exactly about what is
  88. |>    legal according to the standard.  In comp.lang.c (to which this
  89. |>    article is also cross-posted), the discussion should generally be a
  90. |>    bit more open.
  91.  
  92. |>    Thus, for example, in comp.std.c, a program with a variable named far
  93. |>    is illegal, and that is it.  In comp.lang.c (and I hope in its
  94.  
  95. |> Huh? A variable named far is perfectly legal.
  96.  
  97. Typo.  I meant legal.
  98.  
  99. |>    moderated variant), I would hope that someone would point out that,
  100. |>    legal or not, it's going to get you into trouble.
  101.  
  102. |> I hope that situation changes soon in the future. Implementation
  103. |> extensions must not encroach upon user name space: the C standard
  104. |> attempts to formalize the distinction between user and implementation
  105. |> name spaces: compilers ought to follow it. Not only in law, but also
  106. |> in spirit.
  107.  
  108. I agree, but...
  109.  
  110. Try naming a global function read, and see what happens (on most
  111. compilers, anyway).  In fact, the Posix standard requires it, and
  112. thus, you cannot be Posix compliant without encroaching upon the user
  113. name space.  (For example.  I'm sure that most other systems will have
  114. similar constraints.)
  115.  
  116. |> For example, assuming that the concept of a far pointer is truly
  117. |> required (It is really an exceptional circumstance which truly
  118. |> _requires_ it; a compiler should usually figure out whether a near or
  119. |> far pointer will work better: but that is a separate discussion), a
  120. |> compiler should invent a keyword in the implementation name space
  121. |> (e.g. __far) for it. It may provide a non-default switch
  122. |> /backward-compatible to allow it to recognize far as a keyword and
  123. |> treat it as a syntax error if used as a variable name.
  124.  
  125. |> But I agree that discussions in comp.lang.c should also take care of
  126. |> current realities, even if those realities are fossils of an era long
  127. |> past, frozen in time only by the arrogant ignorance of a large body of
  128. |> users with a narrow view to the future.
  129.  
  130. Well, I'm not sure that I'd consider Posix a fossil of an era long
  131. past, although it certainly reflects a long history.
  132.  
  133. I'm not sure where to draw the line.  Discussions of `read' certainly
  134. don't belong in c.l.c.  But simply telling someone that his system is
  135. broken because printf stopped working when he declared a global read
  136. is not going to help anyone, even if, strictly speaking, it is true
  137. according to the standard.
  138.  
  139. I may be oversensitivized to this problem.  My usual hang-outs are the
  140. C++ groups.  Given the speed the C++ standard has evolved, there is no
  141. such thing as a conforming compiler, and most people have to get their
  142. programs working now, and not in 10 years time.  As a result, we do
  143. spend a lot of time talking about compiler idiocyncracies.
  144. --
  145. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  146. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  147. Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
  148.                 -- A la recherche d'une activitΘ dans une region francophone
  149.  
  150.